home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / gfx / show / aMiPEG_1_1_src.lha / aMiPEG_1.1 / src / svideo.s < prev    next >
Text File  |  1997-12-02  |  21KB  |  1,054 lines

  1. ;
  2. ; Some practical assembler utility routines. See sutils.h for corresponding C prototypes.
  3. ; These are mostly called from within video.c as most of them are kinda copy
  4. ; routines which handle cropping and adding together different-sized channels.
  5. ;
  6. ; Michael Rausch  14-4-94  1:14:30
  7. ;
  8.  
  9.     SECTION    text,CODE
  10.  
  11. ER    EQU    -1
  12.  
  13. OK    EQU    1
  14. UNDERFLOW EQU    -2
  15.  
  16.     XREF    @correct_underflow
  17.     XREF    _bitBuffer
  18.     XREF    _bufLength
  19.     XREF    _bitBuffer
  20.     XREF    _bitOffset
  21. ;    XREF    _bitCount    ; ANALYSIS
  22. ;    XREF    _mbCoeffPtr    ; ANALYSIS
  23.  
  24.     XREF    _dct_coeff_first
  25.     XREF    _dct_coeff_next
  26.     XREF    _dct_coeff_tbl_0
  27.     XREF    _dct_coeff_tbl_1
  28.     XREF    _dct_coeff_tbl_2
  29.     XREF    _dct_coeff_tbl_3
  30.  
  31.  
  32.     XREF    _clamp
  33.  
  34.  
  35. ; ***************************************************************
  36.  
  37.  
  38.     XDEF    @next_start_code
  39. @next_start_code:
  40.     moveq    #120,d1            ; was 2
  41.     cmp.l    _bufLength(a4),d1
  42.     ble.s    nsc_nc
  43.     bsr    @correct_underflow
  44. nsc_nc:
  45.     move.l    d2,a1
  46.  
  47.     move.l    _bitOffset(a4),d1
  48.     move.l    _bitBuffer(a4),a0
  49.     move.l    _bufLength(a4),d2
  50.  
  51.     moveq    #7,d0
  52.     and.l    d1,d0
  53.     beq.s    nsc_is_byte_border
  54.     addq.l    #8,d1
  55.     sub.l    d0,d1
  56.     moveq    #32,d0
  57.     cmp.l    d0,d1
  58.     blt.s    nsc_is_byte_border
  59.     sub.l    d0,d1
  60.     addq.l    #4,a0
  61.     subq.l    #1,d2
  62. nsc_is_byte_border:
  63.  
  64.     lsr.l    #3,d1
  65.     add.l    d1,a0            ; a0 is on a longword bound, so align a0 to the byte boundary
  66.  
  67.     lsl.l    #2,d2
  68.     add.l    a0,d2            ; end of the buffer
  69.  
  70.     move.w    (a0)+,d0        ; prefetch 16 bits
  71.  
  72.     moveq    #1,d1
  73. nsc_loop:
  74.     cmp.l    d2,a0
  75.     bge.s    nsc_underflow
  76.     ext.l    d0            ; this one is critical!
  77.     lsl.l    #8,d0
  78.     move.b    (a0)+,d0
  79. ;    tst.l    d0
  80. ;    beq.s    nsc_found
  81.     cmp.l    d1,d0
  82.     bne.s    nsc_loop
  83. nsc_found:
  84.  
  85.     subq.l    #3,a0            ; last 24 bits are the new startcode
  86.     move.l    a0,d1
  87.     and.l    #3,d1
  88.     sub.l    d1,a0            ; new bitBuffer
  89.     lsl.l    #3,d1            ; new bitOffset
  90.     sub.l    a0,d2            ; new bufLength
  91.     lsr.l    #2,d2
  92.  
  93.     move.l    a0,_bitBuffer(a4)
  94.     move.l    d1,_bitOffset(a4)
  95.     move.l    d2,_bufLength(a4)
  96.     move.l    a1,d2
  97.     moveq    #OK,d0
  98.     rts
  99. nsc_underflow:
  100.     move.l    a0,_bitBuffer(a4)    ; i.e. exact end of buffer
  101.     clr.l    _bitOffset(a4)        ; no data available anymore
  102.     clr.l    _bufLength(a4)
  103.     move.l    a1,d2
  104.     moveq    #UNDERFLOW,d0
  105.     rts
  106.  
  107. ; ***************************************************************
  108.  
  109.  
  110.     XDEF    @s_DecodeCBP
  111. @s_DecodeCBP:
  112.     moveq    #9,d0
  113.     lea    _coded_block_pattern,a0
  114.     bra.s    @s_get_byte_huff
  115.  
  116.     XDEF    @sn_DecodeCBP
  117. @sn_DecodeCBP:
  118.     moveq    #9,d0
  119.     lea    _coded_block_pattern,a0
  120.     bra.s    @sn_get_byte_huff
  121.  
  122.  
  123. gsh_x:    move.l    d2,-(sp)
  124.     move.l    a0,-(sp)
  125.     move.l    d0,d2
  126.     bsr    @correct_underflow
  127.     move.l    d2,d0
  128.     move.l    (sp)+,a0
  129.     bra.s    sngsh
  130.  
  131.     XDEF    @s_get_byte_huff
  132. @s_get_byte_huff:
  133.     moveq    #2,d1
  134.     cmp.l    _bufLength(a4),d1
  135.     bgt.s    gsh_x
  136.  
  137.     XDEF    @sn_get_byte_huff
  138. @sn_get_byte_huff:
  139.     move.l    d2,-(sp)
  140. sngsh:
  141.  
  142.     move.l    _bitOffset(a4),d1
  143.     move.l    _bitBuffer(a4),a1
  144.     bfextu    (a1){d1:d0},d2
  145.  
  146.     move.w    (a0,d2.w*2),d0
  147.  
  148.     moveq    #0,d2
  149.     move.b    d0,d2
  150.  
  151. ;    add.l    d2,_bitCount(a4)    ; ANALYSIS
  152.  
  153.     add.l    d1,d2
  154.     moveq    #32,d1
  155.     cmp.l    d1,d2
  156.     blt.s    sgdhw
  157.     sub.l    d1,d2
  158.     addq.l    #4,_bitBuffer(a4)
  159.     subq.l    #1,_bufLength(a4)
  160. sgdhw:
  161.     move.l    d2,_bitOffset(a4)
  162.  
  163.     lsr.w    #8,d0
  164.     extb.l    d0
  165.  
  166.     move.l    (sp)+,d2
  167.     rts
  168.  
  169. ; ***************************************************************
  170.  
  171.     XDEF    @s_DecodeDCTDCSizeLum
  172. @s_DecodeDCTDCSizeLum:
  173.     moveq    #7,d1
  174.     lea    _dct_dc_size_luminance,a1
  175.     bra.s    sdlc
  176.  
  177.     XDEF    @s_DecodeDCTDCSizeChrom
  178. @s_DecodeDCTDCSizeChrom:
  179.     moveq    #8,d1
  180.     lea    _dct_dc_size_chrominance,a1
  181. sdlc:    move.l    d2,-(sp)
  182.     move.l    d3,-(sp)
  183.  
  184.     move.l    _bitOffset(a4),d0
  185.     move.l    _bitBuffer(a4),a0
  186.     moveq    #16,d3
  187.     bfextu    (a0){d0:d3},d2
  188.  
  189.     move.l    d2,d0
  190.     sub.l    d1,d3
  191.     lsr.l    d3,d0
  192.     move.w    (a1,d0.w*2),d0        ; macroval
  193.  
  194.     move.b    d0,d3            ; flushed.l
  195.     lsl.w    d3,d2
  196.     lsr.w    d3,d2            ; mask off the header
  197.  
  198.     lsr.w    #8,d0            ; size
  199.     tst.w    d0            ; necessary ?
  200.     beq.s    cdlflush
  201.  
  202.     add.w    d0,d3
  203.     moveq    #16,d1
  204.     sub.l    d3,d1
  205.     lsr.l    d1,d2            ; trash unused lower bits
  206.  
  207.     subq.l    #1,d0            ; MPEG has some really strange sign extension, just like JPEG! Weirdo!
  208.     btst    d0,d2
  209.     bne    cdlsign
  210.     moveq    #-2,d1
  211.     lsl.l    d0,d1
  212.     or.l    d1,d2
  213.     addq.l    #1,d2
  214. cdlsign: move.l    d2,d0            ; the desired result
  215. cdlflush:
  216.  
  217. ;    add.l    d3,_bitCount(a4)    ; ANALYSIS
  218.  
  219.     add.l    _bitOffset(a4),d3
  220.     moveq    #32,d1
  221.     cmp.l    d1,d3
  222.     blt.s    cdlXw
  223.     sub.l    d1,d3
  224.     addq.l    #4,_bitBuffer(a4)
  225.     subq.l    #1,_bufLength(a4)
  226. cdlXw:
  227.     move.l    d3,_bitOffset(a4)
  228.     move.l    (sp)+,d3
  229.     move.l    (sp)+,d2
  230.     rts
  231.  
  232.  
  233. ; ***************************************************************
  234.  
  235. sgb1:    bsr    @correct_underflow
  236.     bra.s    @sn_get_bits1
  237.  
  238.     XDEF    @s_get_bits1
  239. @s_get_bits1:
  240.     moveq    #2,d1
  241.     cmp.l    _bufLength(a4),d1
  242.     bgt.s    sgb1
  243.  
  244.     XDEF    @sn_get_bits1
  245. @sn_get_bits1:
  246. ;    addq.l    #1,_bitCount(a4)    ; ANALYSIS
  247.     move.l    _bitBuffer(a4),a0
  248.     move.l    _bitOffset(a4),d1
  249.     moveq    #1,d0            ; hmm ?!
  250.     bfextu    (a0){d1:d0},d0
  251.     addq.l    #1,d1
  252.     btst    #5,d1
  253.     beq.s    gb1r
  254.     addq.l    #4,a0
  255.     moveq    #0,d1
  256.     move.l    a0,_bitBuffer(a4)
  257.     subq.l    #1,_bufLength(a4)
  258. gb1r:    move.l    d1,_bitOffset(A4)
  259.     rts
  260.  
  261.  
  262.  
  263. sgbX:    move.l    d0,-(sp)
  264.     bsr    @correct_underflow
  265.     move.l    (sp)+,d0
  266.     bra.s    @sn_get_bitsX
  267.  
  268.     XDEF    @s_get_bitsX
  269. @s_get_bitsX:
  270.     moveq    #2,d1
  271.     cmp.l    _bufLength(a4),d1
  272.     bgt.s    sgbX
  273.  
  274.     XDEF    @sn_get_bitsX
  275. @sn_get_bitsX:
  276. ;    add.l    d0,_bitCount(a4)    ; ANALYSIS
  277.     move.l    _bitOffset(a4),d1
  278.     move.l    _bitBuffer(a4),a0
  279.     move.l    d1,a1
  280.     add.l    d0,a1
  281.     bfextu    (a0){d1:d0},d0
  282.     moveq    #32,d1
  283.     cmp.l    d1,a1
  284.     blt.s    gsbXw
  285.     sub.l    d1,a1
  286.     addq.l    #4,a0
  287.     move.l    a0,_bitBuffer(a4)
  288.     subq.l    #1,_bufLength(a4)
  289. gsbXw:    move.l    a1,_bitOffset(a4)
  290.     rts
  291.  
  292.  
  293. ; ***************************************************************
  294.  
  295. ssb32_ofoi:
  296.     bsr    @correct_underflow        ; ofoi OPT
  297.     bra.s    @sn_show_bits32
  298.  
  299.     XDEF    @s_show_bits32
  300. @s_show_bits32
  301.     moveq    #2,d1
  302.     cmp.l    _bufLength(a4),d1
  303.     bgt.s    ssb32_ofoi
  304.  
  305.     XDEF    @sn_show_bits32
  306. @sn_show_bits32:
  307.     move.l    _bitBuffer(a4),a0
  308.     move.l    _bitOffset(a4),d1
  309.     moveq    #32,d0
  310.     bfextu    (a0){d1:d0},d0
  311.     rts
  312.  
  313.  
  314. ssb_x:    move.l    d0,-(sp)
  315.     bsr    @correct_underflow
  316.     move.l    (sp)+,d0
  317.     bra.s    @sn_show_bitsX
  318.  
  319.     XDEF    @s_show_bitsX
  320. @s_show_bitsX
  321.     moveq    #2,d1
  322.     cmp.l    _bufLength(a4),d1
  323.     bgt.s    ssb_x
  324.  
  325.     XDEF    @sn_show_bitsX
  326. @sn_show_bitsX:
  327.     move.l    _bitOffset(a4),d1
  328.     move.l    _bitBuffer(a4),a0
  329.     bfextu    (a0){d1:d0},d0
  330.     rts
  331.  
  332.  
  333.  
  334. ; ***************************************************************
  335.  
  336.  
  337. sf32_ofoi:
  338.     bsr    @correct_underflow    ; moved away
  339.     bra.s    @sn_flush_bits32
  340.  
  341.     XDEF @s_flush_bits32
  342. @s_flush_bits32:
  343.     moveq    #2,d1
  344.     cmp.l    _bufLength(a4),d1
  345.     bgt.s    sf32_ofoi
  346.  
  347.     XDEF @sn_flush_bits32
  348. @sn_flush_bits32:
  349. ;    add.l    #32,_bitCount(a4)    ; ANALYSIS
  350.     addq.l    #4,_bitBuffer(a4)
  351.     subq.l    #1,_bufLength(a4)
  352.     rts
  353.  
  354.  
  355. sf_outtafoi:
  356.     move.l    d0,-(sp)
  357.     bsr    @correct_underflow    ; moved away, out of flow of instructions
  358.     move.l    (sp)+,d0
  359.     bra.s    @sn_flush_bits
  360.  
  361.     XDEF @s_flush_bits
  362. @s_flush_bits:
  363.     moveq    #2,d1
  364.     cmp.l    _bufLength(a4),d1
  365.     bgt.s    sf_outtafoi
  366.  
  367.     XDEF @sn_flush_bits
  368. @sn_flush_bits:
  369. ;    add.l    d0,_bitCount(a4)    ; ANALYSIS
  370.     add.l    _bitOffset(a4),d0
  371.     moveq    #32,d1
  372.     cmp.l    d1,d0
  373.     blt.s    sbf32
  374.     sub.l    d1,d0
  375.     addq.l    #4,_bitBuffer(a4)
  376.     subq.l    #1,_bufLength(a4)
  377. sbf32:    move.l     d0,_bitOffset(a4)
  378.     rts
  379.  
  380. locallevel:    ds.l    1
  381.  
  382. ; ***************************************************************
  383.  
  384. bgsh_x:    move.l    a0,-(sp)
  385.     move.l    d0,-(sp)
  386.     move.l    a1,-(sp)
  387.     bsr    @correct_underflow
  388.     move.l    (sp)+,a1
  389.     move.l    (sp)+,d0
  390.     bra.s    bsngsh
  391.  
  392.     XDEF    @s_get_bits_huff
  393. @s_get_bits_huff:
  394.     moveq    #2,d1
  395.     cmp.l    _bufLength(a4),d1
  396.     bgt.s    bgsh_x
  397.  
  398.     XDEF    @sn_get_bits_huff
  399. @sn_get_bits_huff:
  400.     move.l    a0,-(sp)
  401. bsngsh:
  402.  
  403.     move.l    _bitOffset(a4),d1
  404.     move.l    _bitBuffer(a4),a0
  405.     bfextu    (a0){d1:d0},d2
  406.  
  407.     move.l    (sp)+,a0
  408.  
  409.     move.w    (a1,d2.w*2),d0
  410.     bmi.s    gbh_error
  411.  
  412.     moveq    #0,d2
  413.     move.b    d0,d2
  414.  
  415. ;    add.l    d2,_bitCount(a4)    ; ANALYSIS
  416.  
  417.     add.l    d1,d2
  418.     moveq    #32,d1
  419.     cmp.l    d1,d2
  420.     blt.s    bsgdhw
  421.     sub.l    d1,d2
  422.     addq.l    #4,_bitBuffer(a4)
  423.     subq.l    #1,_bufLength(a4)
  424. bsgdhw:
  425.     move.l    d2,_bitOffset(a4)
  426.  
  427.     lsr.w    #8,d0
  428.     moveq    #0,d1
  429.     lsr.w    #1,d0
  430.     addx.w    d1,d1
  431.     move.l    d1,(a0)            ; save intra
  432.     rts
  433.  
  434. gbh_error:
  435.     moveq    #1,d0
  436.     move.l    d0,(a0)
  437.     rts
  438.  
  439.  
  440.  
  441. ; ***************************************************************
  442.  
  443. ;void PMB2_reconstruct(char *dest, char *dest1, char *source, char *source1, int row_incr);
  444.  
  445.     XDEF    _PMB2_reconstruct
  446. _PMB2_reconstruct:
  447.     subq.l    #2,d0            ; (int*)   correct row_size
  448.     lsl.l    #2,d0
  449.     moveq    #7,d1
  450. pmb2_all_rows:
  451.     move.l    (a2)+,(a0)+
  452.     move.l    (a2)+,(a0)+
  453.     move.l    (a3)+,(a1)+
  454.     move.l    (a3)+,(a1)+
  455.     add.l    d0,a0
  456.     add.l    d0,a1
  457.     add.l    d0,a2
  458.     add.l    d0,a3
  459.     dbra    d1,pmb2_all_rows
  460.     rts
  461.  
  462. ; ***************************************************************
  463.  
  464. ;void PMB1_reconstruct(char *dest, char *source, int row_incr);
  465.  
  466.     XDEF    _PMB1_reconstruct
  467. _PMB1_reconstruct:
  468.     subq.l    #4,d0            ; correct row_size
  469.     lsl.l    #2,d0
  470.     moveq    #15,d1
  471. pmb1_all_rows